//
//  SinaAccountModel.swift
//  SinaWeiBo
//
//  Created by 刘世瑛 on 16/1/21.
//  Copyright © 2016年 刘世瑛. All rights reserved.
//

import UIKit

class SinaAccountModel: NSObject ,NSCoding{

    var access_token:String?
    var expires_in:NSTimeInterval = 0{
        didSet{
            expires_date = NSDate(timeIntervalSinceNow: expires_in)
        }
    }
//    var remind_in:NSTimeInterval = 0
    var uid:String?
    var screen_name:String?
    var profile_image_url:String?
    var expires_date:NSDate?
    
    init(dic:[String: AnyObject])
    {
        super.init()
        setValuesForKeysWithDictionary(dic)
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    //解档
    required init?(coder aDecoder: NSCoder) {
       self.access_token =  aDecoder.decodeObjectForKey("access_token") as? String
//       self.expires_in =  aDecoder.decodeObjectForKey("expires_in") as! NSTimeInterval
      self.uid =   aDecoder.decodeObjectForKey("uid") as? String
       self.screen_name =  aDecoder.decodeObjectForKey("screen_name") as? String
        self.profile_image_url =  aDecoder.decodeObjectForKey("profile_image_url") as? String
       self.expires_date =  aDecoder.decodeObjectForKey("expires_date") as? NSDate

    }
    //归档
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(self.access_token, forKey: "access_token")
//        aCoder.encodeObject(self.expires_in, forKey: "expires_in")
        aCoder.encodeObject(self.uid, forKey: "uid")
        aCoder.encodeObject(self.screen_name, forKey: "screen_name")
        aCoder.encodeObject(self.profile_image_url, forKey: "profile_image_url")
        aCoder.encodeObject(self.expires_date, forKey: "expires_date")


    }
    
    
    //归档保存
     func saveCoder()
    {
        let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first! as NSString
        let endPath = path.stringByAppendingPathComponent("accountModel.plist")
        print(endPath)
        NSKeyedArchiver.archiveRootObject(self, toFile: endPath)
        
    }
    
    
    
}
